<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--<%@ include file="../include/admincontent.jsp" %>--%>
<link rel="stylesheet" href="../resources/js/plugins/layui/css/layui.css"/>
<link rel="stylesheet" href="../resources/css/knowlegPoints.css"/>
<link rel="stylesheet" href="../resources/css/index.css"/>

<div id="selectTopic" >
    <input type="hidden" name="tidInput" value=${tid} >
    <input type="hidden" name="pidInput" value=${pid} >
    <input type="hidden" name="majorInput" value="${major}" >
    <input type="hidden" name="kidInput" value="${kid}" >
    <form id="searchfrom" action="">
        <table width="100%" class="treeTable searchform" cellpadding="0" cellspacing="0" style=" margin-bottom:10px;">
            <thead>
            <tr>
                <td width="60">知识点：</td>
                <td width="200">
                    <select id="kidName" name="kidName">
                        <option value="${kidnames}">${kidnames}</option>
                        <%--<c:forEach var="knowManageList" items="${kidnames}" varStatus="item" >
                            <c:choose>
                                <c:when test="${knowManageList!=null}">
                                    <option value="${knowManageList.name}">${knowManageList.name}</option>
                                </c:when>
                            </c:choose>
                        </c:forEach>--%>
                    </select>
                </td>
                <td width="45">难度：</td>
                <td width="80">
                    <select id="level" name="level">
                        <option value="-1">全部</option>
                        <option value="0">低难度</option>
                        <option value="1">中难度</option>
                        <option value="2">高难度</option>
                    </select>
                </td>
                <td width="60">关键字：</td>
                <td width="150" ><input type="text" name="key" style="height: 24px"/></td>
                <td >
                    <button id="searchbtn" class="search" type="button" style="width: 70px">
                        <em class="ico16 search_16"></em>
                        <span class="menu_span" title="查询">查询</span>
                    </button>
                </td>
            </tr>
            </thead>
        </table>
    </form>
    <table id="topicListTable" lay-filter="topicListTable" class="treeTable" width="100%" cellpadding="0" cellspacing="0"></table>
</div>

<script type="text/javascript" src="../resources/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../resources/js/plugins/layui/layui.js"></script>
<script type="text/javascript" src="../resources/js/actions.js"></script>
<script src="../resources/js/fadeInout.js" type="text/javascript"></script>

<script type="text/javascript" language="javascript">

   var getClickKidName;
   var getClickContent;
   var getClickRel;
   var getClickID;
   var getClickNum;
   
   var tKonwledge;
   var tLevel;
   var tkey;
   var major;
   var tid;
   var pid;
   var kid;
   var relDat;
   var relTemp;

   var changeFlag = false;
   var changeList = [];
   var changeNum = 0;

$(function () {

       tKonwledge = $("#kid").val();
       tLevel = $("#Level").val();
       tkey = $("input[name='key']").val();
       tid =  $("input[name='tidInput']").val();
       pid =  $("input[name='pidInput']").val();
       major = $("input[name='majorInput']").val();
        kid = $("input[name='kidInput']").val();
       relDat = "tid="+tid+"&pid="+pid+"&kid="+kid+"&major="+major;
        relTemp = "tid="+tid+"&pid="+pid;

       layui.use('table', function () {
           var table = layui.table;

           table.render({
               elem: '#topicListTable',
               url: '/PaperManager/SelectQuestion?'+relDat, //数据接口
               page: true,
               cols: [[
                   { field: 'name', title: '题目名称', },
                   { field: 'type', title: '题型', width: 120 },
                   { field: 'knowledge', title: '知识点', width: 200 },
                   { field: '', title: '', width: 80,event:'btn_choose',templet: function(d){
                       return '<a href="javascript:void(0);" style="color: blue"> 选择 </a>';
                   }},
               ],],
               where:{
                   key:{
                       tKonwledge:tKonwledge,
                       tLevel:tLevel,
                       tkey:tkey,
                   }
               },
               done: function (res, curr, count){
               }
           });

           $("#searchbtn").on('click', () => {
               tKonwledge = $("#kidName").val();
               tLevel = $("#level").val();
               tkey = $("input[name='key']").val();

               table.reload('topicListTable', {
                   url:'/PaperManager/SelectQuestion?'+relDat
                   ,method: 'get'
                   ,page:  {
                       curr: 1 //重新从第 1 页开始
                   }
                   ,where: {
                       key: {
                           tKonwledge:tKonwledge,
                           tLevel:tLevel,
                           tkey:tkey,
                       }
                   }
               }, 'data');
           });

           table.on('tool(topicListTable)', function (obj) {
               if (obj.event === 'btn_choose') {
                   relData =  $("input[name='relData']").val();
                   var  getData = table.cache["topicListTable"];
                   var  getDataCache = parent.layui.table.cache['cacheTable']

                 //  var getData0 = getTableContent(getClickID);
                   var flags = false;
                   for(var j = 0;j < getDataCache.length;j++){
                       if(obj.data.rel === getDataCache[j].rel){
                           flags = true;
                           break;
                       }
                   }
                   if(flags)
                       layer.msg("不能选择重复的题目!",{icon:2});
                   else {

                       for(var j=0;j<getDataCache.length;j++){
                           if(relTemp === getDataCache[j].rel){
                               getDataCache[j].rel = obj.data.rel;
                               getDataCache[j].name = obj.data.name;
                               getDataCache[j].knowID = obj.data.knowID;
                               getDataCache[j].knowledge = obj.data.knowledge;
                               getDataCache[j].changed = true;
                               break;
                           }
                       }
                       parent.layui.table.cache['cacheTable'] = getDataCache;
                       parent.layer.closeAll();
                   }
               }
           });
       })

})
</script>